package com.demo.api.controller.open.user;

import com.demo.api.cache.DeptCache;
import com.demo.api.cache.MenuCache;
import com.demo.api.controller.BaseController;
import com.demo.api.service.user.IUserSystemService;
import com.demo.api.vo.user.UserLogin;
import com.demo.core.annotation.AuthToken;
import com.demo.core.entity.DeptTree;
import com.demo.core.entity.MenuTree;
import com.demo.core.response.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @author Tan-Bowen
 * @version 1.0
 * @description TODO
 * @date 2021/8/12 11:29
 */
@Api(value = "用户管理开放接口", tags = "用户中心-开放接口" )
@RestController
@RequestMapping("/open/user")
public class UserOpenController extends BaseController {

    @Resource
    private IUserSystemService userSystemService;

    @Resource
    private DeptCache deptCache;

    @Resource
    private MenuCache menuCache;


    @AuthToken(checkToken = false,checkPower = false)
    @PostMapping("/platformLogin")
    @ApiOperation("平台用户登录")
    public ApiResponse<UserLogin.Response> platformLogin(@Validated UserLogin.Request login, HttpServletRequest request){
        return ApiResponse.success(userSystemService.platformLogin(login,getIpAddr(request)));
    }

    @AuthToken(checkToken = false,checkPower = false)
    @PostMapping("/test")
    @ApiOperation("test")
    public ApiResponse<List<DeptTree>> test(@RequestParam("pid")Long pid){
        return ApiResponse.success(deptCache.getTreeDept());
    }


}
